// Copyright (c) 2013, Webit Team. All Rights Reserved.
package cn.iver.ext.webit.script;

import cn.iver.common.Const;
import com.jfinal.core.JFinal;
import webit.script.Engine;
import webit.script.Initable;
import webit.script.core.NativeFactory;
import webit.script.global.GlobalManager;
import webit.script.global.GlobalRegister;
import webit.script.util.SimpleBag;

/**
 *
 * @author zqq90 <zqq_90@163.com>
 */
public class DefaultGlobalRegister implements GlobalRegister, Initable {

    private NativeFactory nativeFactory;

    public void init(Engine engine) {
        this.nativeFactory = engine.getNativeFactory();
    }

    public void regist(GlobalManager manager) {

        SimpleBag constBag = manager.getConstBag();
        
        constBag.set("basepath", JFinal.me().getServletContext().getContextPath());
        constBag.set("v", Const.TIMESTAMP);
        constBag.set("printTime", this.nativeFactory.createNativeMethodDeclare(MethodUtil.class, "getNiceDate", new Class[]{Object.class}));
        //constBag.set("isSame", this.nativeFactory.createNativeMethodDeclare(MethodUtil.class, "isSame", new Class[]{String.class, String.class, Object.class}));
    }

}
